/*
 * EventHandler.cpp
 *
 *  Created on: 08/01/2012
 *      Author: Graciela
 */

#include "EventHandler.h"
using namespace std;

EventHandler::EventHandler() {
}

EventHandler::~EventHandler() {
}

void EventHandler::addKeyListener(KeyListener * listener) {
	keyListeners.push_back(listener);
}

void EventHandler::update() {
	SDL_Event event;
	while (SDL_PollEvent(&event)) {
		if (event.type == SDL_KEYDOWN) {
			triggerOnKeyDown(&event);
		} else if (event.type == SDL_KEYUP)
			triggerOnKeyUp(&event);
	}
}

void EventHandler::triggerOnKeyDown(SDL_Event * event) {
	list<KeyListener *>::iterator key;
	for (key = keyListeners.begin(); key != keyListeners.end(); key++)
		(*key)->onKeyDown(event);
}

void EventHandler::triggerOnKeyUp(SDL_Event * event) {
	list<KeyListener *>::iterator key;
	for (key = keyListeners.begin(); key != keyListeners.end(); key++)
		(*key)->onKeyUp(event);
}
